package com.hk.Mgr.web.controller.app.yingmi;

import com.hk.api.ProcessAPI;
import com.hk.base.BaseCtrl;
import com.hk.commons.enm.ShareTypeEnum;
import com.hk.commons.enm.YingmiTransactionType;
import com.hk.commons.vo.JsonResult;
import com.hk.yingmi.YingmiOpenAPIConstant;
import org.apache.commons.lang3.StringUtils;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletRequest;
import java.util.ArrayList;
import java.util.HashMap;

/**
 * Created by Antinomy on 17/8/25.
 */
@RestController
@RequestMapping(value = BaseCtrl.App)
public class YingmiOptionDetailsController {

    @RequestMapping(value = YingmiOpenAPIConstant.SHARE_TYPE, method = RequestMethod.GET)
    @ResponseBody
    public JsonResult share_type(HttpServletRequest request, String filter) {
        ProcessAPI api = (jsonResult, validate) -> {

            ArrayList result = new ArrayList();

            for (ShareTypeEnum type : ShareTypeEnum.values()) {

                if (StringUtils.isBlank(filter) || filter.indexOf(type.getCode()) >= 0) {

                    HashMap item = new HashMap();
                    item.put("name", type);
                    item.put("code", type.getCode());
                    item.put("msg", type.getMsg());
                    result.add(item);
                }

            }

            jsonResult.result = result;
            jsonResult.size = (long) result.size();
        };

        return api.process(request);
    }

    @RequestMapping(value = YingmiOpenAPIConstant.TRANSACTION_TYPE, method = RequestMethod.GET)
    @ResponseBody
    public JsonResult transaction_type(HttpServletRequest request) {
        ProcessAPI api = (jsonResult, validate) -> {

            ArrayList result = new ArrayList();

            for (YingmiTransactionType type : YingmiTransactionType.values()) {
                HashMap item = new HashMap();
                item.put("name", type);
                item.put("value", type.getValue());
                item.put("code", type.getCode());
                result.add(item);
            }

            jsonResult.result = result;
            jsonResult.size = (long) result.size();
        };

        return api.process(request);
    }
}
